/*
  学习目标：底层原理-setState第二种写法
  语法: setState((旧的state) => 新的state)
  特点: 连续调用会产生合并效果
  合并: 上一次的计算结果, 会传给下一次的计算参数
  目的: 减少操作dom次数, 节省性能
*/

import React, { Component } from 'react';

export default class App extends Component {
  state = {
    count: 0,
  };

  handleAdd = () => {
    this.setState((preState) => {
      return {
        count: preState.count + 1,
      };
    });
    this.setState((preState) => {
      return {
        count: preState.count + 2,
      };
    });
    this.setState((preState) => {
      return {
        count: preState.count + 3,
      };
    });

    console.log('this.state.count  ----->  ', this.state.count);
  };

  render() {
    console.log('render执行了  ----->  ');
    const { count } = this.state;

    return (
      <div>
        App
        <h1>{count}</h1>
        <button onClick={this.handleAdd}>点我</button>
      </div>
    );
  }
}
